function [ dropPos ] = bomberGeneric( graph, shipPos, lastShipPos, lag, turn, pShip )
%% The function bomberGeneric simulates a bomber which oberserves obsTime
%% steps the moves of the ship and uses the counted numbers of going
%% forward, staying still and going backward to create probabilities for
%% each possible bombing position. 
%%

dropPos = 0;
obsTime = 500;
nOut = sum(graph(1,:))-1;
%if stay
if graph(1,1) == 1
    nOut = nOut - 1;
end

if pShip < 0
    persistent nForward;
    persistent nBack;
    persistent nStay;
    if turn == 1
        nForward = 0;
        nBack = 0;
        nStay = 0;
    end
    
    %get the data
    if turn <= obsTime
        %COUNT nForward/nBack
        lastPos = [shipPos; lastShipPos'];
        if lastPos(1) == lastPos(2) && lastPos(1) ~= 0
            nStay = nStay + 1;
        elseif (length(unique(lastPos)) <= 2 && ~any(lastPos==0))  %A-B-A
            nBack = nBack + 1;
        else  %A-B-C
            nForward = nForward + 1;
        end
        if turn==obsTime
            pForward = nForward / (obsTime*nOut);
            pStay = nStay / obsTime;
            pBack = nBack / obsTime;
        end
    end
else
    pForward = pShip;
    pBack = 1-pShip*nOut;
    pStay = 0;
end
%play with the data
if turn>=obsTime || pShip >= 0
    p = zeros(length(graph),1);
    pmulti = 1;
    akPos = 1;
    lastPos = 2;
    p = getPositionProbabilities(graph, akPos, lastPos, lag, pmulti, p, pForward, pBack, pStay);
    %highest probability
%     hProb = 0;
%     for i=1:length(p)
%        if p(i,1) >= hProb
%           hProb = p(i,1);
%           dropPos = i;
%        end
%     end
    %position by random number
    rd = rand(1);
    sp = 0;
    for i=1:length(p)
        sp = sp + p(i,1);
        if sp > rd
            dropPos = i;
            break;
        end
    end
end

end


